<extend name="Base/base" />
<block name='head'>
    <link rel="stylesheet" href="/Public/Admin/css/personal.css"/>
    <!--<script src="/Public/static/layer/layer.js"></script>-->
    <!--文件上传-->
    <script type="text/javascript" src="/Public/Cropper/js/ajaxfileupload.js" ></script>
    <style>
        .textarea{height:50px;width:90%}
        .checkCont p{float:left;}
        .checkCont a{margin-left:10px;display: inline-block;}
        .fujian{margin:0;}
        .c-red{color:red}
        .pointer{cursor: pointer}
        .icon-date{
            background:url('/Public/Admin/images/date.png') no-repeat right center;
            width: 25px;
            height: 25px;
            position: absolute;
            right: 8px;
            top: 6px;
            cursor:pointer;
        }
    </style>
</block>
<block name="content"> 
    <section class="layui-larry-box">
        <div class="larry-personal">
            <div class="layui-tab inputArea">
                <blockquote class="layui-elem-quote news_search">
                    <div class="layui-inline">
                        <a class="layui-btn layui-btn-normal newsAdd_btn" href="{:U('newsManage',array('type_id'=>$type_id))}">返回</a>
                    </div>
                </blockquote>
                <!-- 表单项 -->
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">新闻类型</label>
                        <div class="layui-input-block">
                            <select name="type_id" class="layui-input search_input type_id">
                                <foreach name="news_code" item="code">
                                    <option value="{$code.code_no}" {$type_id == $code['code_no'] ? 'selected' : ''}>{$code.code_name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label"><span class="c-red">*</span>新闻标题</label>
                        <div class="layui-input-block">
                            <input name="subject" placeholder="请输入新闻标题..." class="layui-input" value='{$info.subject}'>
                            <span class="errMsg"></span>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">按部门发布
                            <p style='font-size:10px;color: #1781d0;' class="pointer" id="href_txt"><if condition='$info["priv_id"] eq "" or $info["user_id"] eq ""'>按人员或角色发布<else />隐藏按人员或角色发布</if></p>
                        </label>
                        <div class="layui-input-block layui-input checkCont" style="width:90%">
                            <p class="textarea depart addDept">
                                <span></span>
                            <foreach name="to_ids" item="dept">
                                <span>
                                    <a>{$dept|getDeptName}</a>
                                    <img class="pointer delOperator" data-id="{$dept}" src="/Public/Index/img/close_red.png" alt="close" width="12">
                                    <input type="hidden" name="dept_ids[]" value="{$dept}">
                                    <input type="hidden" name="dept_names[]" value="{$dept|getDeptName}">
                                </span>
                            </foreach>
                            </p>
                            <!--<a class="arrow pointer addDept">&#xe638;</a>-->
                            <!--<a class="pointer delData">清空</a>-->
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text" id='rang_role' <if condition='$info["priv_id"] eq ""'>style="display:none;"</if>>
                        <label class="layui-form-label">按角色发布</label>
                        <div class="layui-input-block layui-input checkCont value" style="width:90%">
                            <p class="textarea priv addPriv" data-id="1" data-key="priv_id">
                                <span ></span>
                            <foreach name="priv_ids" item="part">
                                <span class="one-name">
                                    <a>{$part|getPrivName}</a>
                                    <img class="pointer delOperator" data-id="{$part}" src="/Public/Index/img/close_red.png" alt="close" width="12">
                                    <input type="hidden" name="priv_id[]" value="{$part}">
                                    <input type="hidden" name="priv_names[]" value="{$part|getPrivName}">
                                </span>
                            </foreach>
                            </p>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text" id='rang_user' <if condition='$info["user_id"] eq ""'>style="display:none;"</if>>
                        <label class="layui-form-label">按人员发布</label>
                        <div class="layui-input-block layui-input checkCont value" style="width:90%">
                            <p class="textarea addUser addUser_1" data-id="1" data-key="user_id">
                                <span></span>
                            <foreach name="user_ids" item="person">
                                <span class="one-name">
                                    <a>{$person|getChineseName}</a>
                                    <img class="pointer delOperator" data-id="{$person}" src="/Public/Index/img/close_red.png" alt="close" width="12">
                                    <input type="hidden" name="user_id[]" value="{$person}">
                                    <input type="hidden" name="user_names[]" value="{$person|getChineseName}">
                                </span>
                            </foreach>
                            </p>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-block" style="width:175px;">
                            <i class='icon-date datepickerInput diary_date' data-type='2'></i>
                            <input type="text" name="news_time" autocomplete="off" <if condition='$news_id neq ""'>value="{$info.news_time}"<else />value="{:date('Y-m-d H:i:s')}"</if> class="layui-input search_input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">评论</label>
                        <div class="layui-input-block">
                            <select name="anonymity_yn" class="layui-input search_input type_id">
                                <option value="0" {$info.anonymity_yn == 0 ? 'selected' : ''}>实名评论</option>
                                <option value="1" {$info.anonymity_yn == 0 ? 'selected' : ''}>匿名评论</option>
                                <option value="2" {$info.anonymity_yn == 0 ? 'selected' : ''}>禁止评论</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">新闻内容</label>
                        <div class="layui-input-block">
                            <textarea name="content" id="content">{$info.content}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">新闻图片</label>
                        <div class="layui-input-block">
                            <a href="#" id="upload" style='margin-top: 7px;display: inline-block;font-size: 12px;'><span class="fj"><img src="/Public/Admin/images/add.png"> 上传图片<b style="color:red">（请上传497*211像素的图片）</b></span></a>
                            <div class="filename-cont">
                                <span><if condition="$info.uploads neq ''">{$info.uploads}<img src="/Public/Index/img/close.png" style="width:15px" class="pointer delfile" data-fileurl="{$info.uploads_url}"/></if></span>
                            </div>
                            <input type="file" id="inputImage" name='imgfile' style="display:none">
                            <input type="hidden" id="filename" name="uploads" value="{$info.uploads}">
                            <input type="hidden" id="fileurl" name="uploads_url" value="{$info.uploads_url}">
                            <input type="hidden" name="url" value="{:U('Base/delFile',array('table'=>'news','field'=>'news_id','id'=>$news_id))}">
                        </div>
                    </div>   
                    <div class="layui-form-item">
                        <label class="layui-form-label">关键词</label>
                        <div class="layui-input-block">
                            <input name="keyword" placeholder="" class="layui-input" value='{$info.keyword}' style='display: inline;width: 70%;'>&nbsp;&nbsp;(多个关键词请用,分隔)
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否首页显示</label>
                        <div class="layui-input-block level">
                            <lable class="input_lable">
                                <input name="is_show" type="radio" id="sex-1" value="1" {$info['is_show'] == 1 ? 'checked' :''}>
                                <label for="sex-1">是</label>
                            </lable>
                            <lable class="input_lable">
                                <input type="radio" id="sex-2" value="0" name="is_show" {$info['is_show'] == 0 ? 'checked' :''}>
                                <label for="sex-2">否</label>
                            </lable>
                            <b style="color:red">（选择首页显示时，请选择对全体部门发布）</b>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <a class="layui-btn btn-submit ajax-post" data-url="{:U('saveNews')}" data-form="">提交</a>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                    <input type='hidden' name='news_id' value='{$info.news_id}'>
                </form>
            </div>
        </div>
    </section>
</block>
<block name="script">
    <script type="text/javascript" src="/Public/Admin/js/erp.js"></script>
    <script type="text/javascript" src="/Public/Admin/js/common.js" ></script>
    <!--编辑器-->
    <link rel="stylesheet" href="__PUBLIC__/static/ueditor/themes/default/css/ueditor.css"/>
    <script type="text/javascript" src="__PUBLIC__/static/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__PUBLIC__/static/ueditor/ueditor.all.min.js"></script>

    <script type="text/javascript">
        $(initSave())
        $(dateTime(2));
        $(initUpload("{:U(CONTROLLER_NAME.'/upload')}", "news"));
        $('#href_txt').on('click', function () {
            var pra = $('#href_txt').text().indexOf("隐藏");
            if (pra < 0) {
                $('#rang_user').show();
                $('#rang_role').show();
                $('#href_txt').text("隐藏按人员或角色发布");
            } else {
                $('#rang_user').hide();
                $('#rang_role').hide();
                $('#href_txt').text("按人员或角色发布");
            }
        })
        var width = $('.editorArea').width();
        var ue = UE.getEditor('content', {
            initialFrameWidth: width,
            initialFrameHeight: 200,
            toolbars: [[
                    "source", "undo", "redo", "insertunorderedlist", "insertorderedlist", "unlink", "link",
                    "searchreplace", "preview", "pagebreak", "simpleupload", "emotion",
                    "date", "time", "horizontal", "pasteplain",
                    "bold", "italic", "underline", "strikethrough", "forecolor", "backcolor",
                    "superscript", "subscript", "justifyleft", "justifycenter", "justifyright", "justifyjustify",
                    "formatmatch", "removeformat", "lineheight", "fontfamily", "fontsize",
                ]],
        });

        $('.ajax-post').on('click', function () {
            var flag = true;
            if ($('input[name="SUBJECT"]').val() == '') {
                var msg = '新闻标题不能为空！'
                $('input[name="SUBJECT"]').next().text(msg);
                flag = false;
            } else {
                $(this).next().text('');
            }
            if ($('input[name="is_show"]').val() == 1) {
                var img = $('.filename-cont span img').attr('src');
                if (img == 'undefined') {
                    layer.msg('请上传新闻图片！', {icon: 5});
                    flag = false;
                }
            }

            if (flag == false) {
                $(this).removeClass('btn-submit');
            } else {
                $(this).addClass('btn-submit');
            }
        })

    </script>    

</block>
